﻿
var App_AttributeModel = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: "属性",
		winid:'App_Attribute_EditForm',
		formid:'App_Attribute_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/sysmgr/attribute', 
    title: "系统基础属性",
    idField: "attrId",
    titleField: "attrCode",
    toolbar: 'App_Attribute_Toolbar',
    datagrid: 'App_Attribute_Grid' 
}); 
 
App_AttributeModel.reload =function() {
	fun_ReloadApp_AttributeList();
	  $('#App_Attribute_EditForm').dialog('close'); 
} 


function fun_FindRowById(id) {
    var cRows = $('#App_Attribute_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][App_AttributeModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function fun_ShowApp_AttributeEditForm(id) {  
    App_AttributeModel.selRow = fun_FindRowById(id);
    if (App_AttributeModel.selRow == null) {
    	App_AttributeModel.selRow={};
        App_AttributeModel.postAction = 'add';
    }
    else {
        App_AttributeModel.postAction = 'update';
    } 
      
    $('#App_Attribute_EditForm_fm').form('clear' );
    $('#App_Attribute_EditForm_fm').form('load', App_AttributeModel.selRow);
    $('#App_Attribute_EditForm').dialog({
        top: "50px",
        resizable: true,
        maximizable: true,
        height:360
    })
    .dialog('open')
    .dialog('setTitle', (App_AttributeModel.postAction == 'Add') ? '新增' + App_AttributeModel.title : '修改' + App_AttributeModel.selRow[App_AttributeModel.titleField]);
}
function fun_SaveApp_Attribute() {
	App_AttributeModel.submit();
	
}
function fun_DelApp_Attribute( id,title) {
	App_AttributeModel.del(id,title);
} 

function fun_App_AttributeSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#App_Attribute_Grid').datagrid('reload');
    }

}
 
function fun_ReloadApp_AttributeList() {
    $('#App_Attribute_Grid').datagrid('reload');
}
 


$(function () {   
    $('#App_Attribute_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        fitColumns: true,
        pagination: true, //分页控件 
        method: 'post',
        idField: App_AttributeModel.idField,
        treeField: App_AttributeModel.titleField,
        url: Onluy.basePath()+App_AttributeModel.url+'/list',
        loader:App_AttributeModel.Loader,
        toolbar: '#App_Attribute_Toolbar', 
        columns: [
            [
           { title: '属性编码', field: 'attrCode', width: 180, sortable: true, rowspan: 2 },
			        { title: '基础信息', colspan: 2 }, 
                    {
                        field: 'Remove_Tag', title: '状态', width: 100, align: 'center', rowspan: 2,
                        formatter: function (value, rec) {
                            var start = new Date( );
                            var end = new Date(rec['endDate']);
                            if (start < end) {
                                return '<span style="color:green">生效</span>';
                            }
                            else {
                                return '<span style="color:red">失效</span>';
                            }
                        }
                    },
                    {
                        field: 'ordernum', title: '排序', width:50, align: 'center', rowspan: 2
                    },
					{
					    field: 'opt', title: '操作', width: 100, align: 'center', rowspan: 2,
					    formatter: function (value, rec) {
					        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="fun_ShowApp_AttributeEditForm(\'' + rec[App_AttributeModel.idField] + '\');"   />'
                                + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="fun_DelApp_Attribute(\'' + rec[App_AttributeModel.idField] + '\',\'' + rec[App_AttributeModel.titleField] + '\');"  />';
					    }
					}
            ], [ 
					{ field: 'attrValue', title: '属性默认值', width: 300 },
					{ field: 'attrMemo', title: '属性说明', width: 200 },
 
            ]
        ],

        
        onLoadError: function (res) {
        	App_AttributeModel.ShowException(res); 
        },
        onLoadSuccess: function (data) {
             if(data.success){
        		
        	}
        	else{
        		 $.messager.alert('提示', data.msg );
        	} 
        },
        onDblClickRow: function (rowIndex, rowData) {
            fun_ShowApp_AttributeEditForm(rowData[App_AttributeModel.idField]);
        },
        onBeforeLoad: function (param) { 
            param['catchKey'] = Math.random();
            param['name'] = $('#App_Attribute_ss').searchbox('getName');
            param['value'] = $('#App_Attribute_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#App_Attribute_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10  
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表  
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});

